package com.hotel.controller;



import com.hotel.response.Result;
import com.hotel.service.AliOssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;



@RestController
@CrossOrigin
@RequestMapping("/upload")
public class AliController {

    @Autowired
    private AliOssService aliOssService;

    @PostMapping("/uploadImgFile")
    public Result uploadImgFile(MultipartFile file,String pathName){
        String s = aliOssService.upload(file,pathName);
        System.out.println(s);
        return Result.ok().data("url",s);
    }

    @PostMapping("/deleteImgFile")
    public Result deleteImgFile(String file){
        try {
            String[] split = file.split(".com/");
            aliOssService.deleteFile(split[1]);
            return Result.ok();
        }catch (Exception e){
            return Result.error();
        }

    }



}
